package com.aidex.common.core.service.impl;

import com.aidex.common.core.service.BasicService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;

@Transactional(readOnly = true)
public abstract class BasicServiceImpl<M extends BaseMapper<T>, T extends Serializable> implements BasicService<T> {
    @Autowired
    protected M mapper;

    @Transactional
    public int insert(T entity) {
        return this.mapper.insert(entity);
    }

    @Transactional
    public int deleteById(Serializable id) {
        return this.mapper.deleteById(id);
    }

    @Transactional
    public int deleteByMap(Map<String, Object> columnMap) {
        return this.mapper.deleteByMap(columnMap);
    }

    @Transactional
    public int delete(Wrapper<T> queryWrapper) {
        return this.mapper.delete(queryWrapper);
    }

    @Transactional
    public int deleteBatchIds(Collection<? extends Serializable> idList) {
        return this.mapper.deleteBatchIds(idList);
    }

    @Transactional
    public int updateById(T entity) {
        return this.mapper.updateById(entity);
    }

    @Transactional
    public int update(T entity, Wrapper<T> updateWrapper) {
        return this.mapper.update(entity, updateWrapper);
    }

    public T selectById(Serializable id) {
        return this.mapper.selectById(id);
    }

    public List<T> selectBatchIds(Collection<? extends Serializable> idList) {
        return this.mapper.selectBatchIds(idList);
    }

    public List<T> selectByMap(Map<String, Object> columnMap) {
        return this.mapper.selectByMap(columnMap);
    }

    public T selectOne(Wrapper<T> queryWrapper) {
        return this.mapper.selectOne(queryWrapper);
    }

    public Integer selectCount(Wrapper<T> queryWrapper) {
        return this.mapper.selectCount(queryWrapper);
    }

    public List<T> selectList(Wrapper<T> queryWrapper) {
        return this.mapper.selectList(queryWrapper);
    }

    public List<Map<String, Object>> selectMaps(Wrapper<T> queryWrapper) {
        return this.mapper.selectMaps(queryWrapper);
    }

    public List<Object> selectObjs(Wrapper<T> queryWrapper) {
        return this.mapper.selectObjs(queryWrapper);
    }

    public <E extends IPage<T>> E selectPage(E page, Wrapper<T> queryWrapper) {
        return this.mapper.selectPage(page, queryWrapper);
    }

    public <E extends IPage<Map<String, Object>>> E selectMapsPage(E page, Wrapper<T> queryWrapper) {
        return this.mapper.selectMapsPage(page, queryWrapper);
    }
}
